#
#  Copyright (C) 2009 GSyC/LibreSoft
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
#    Author : Jose Antonio Santos Cadenas <jcaden __at__ gsyc __dot__ es>
#

from django.conf.urls.defaults import *
import os
from os.path import join

#from user.views import *
#from backend.views import *
from settings import MEDIA_ROOT, APPS_DIR, BASEDIR

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^server/', include('server.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/(.*)', admin.site.root),

    #(r'^$', login),
    #(r'^user/register/$',register),
    

    #(r'^user/(?P<user>[-a-z]+)/location/$', location),
    #(r'^user/(?P<user>[-a-z]+)/location/movistar/search/$', searchMovistar),
    #(r'^user/(?P<user>[-a-z]+)/location/movistar/auth/$', authMovistar),
    #(r'^user/(?P<user>[-a-z]+)/location/movistar/forbid/$', forbidMovistar),
    #(r'^user/(?P<user>[-a-z]+)/location/iploc/$', geoiploc),
    #(r'^user/(?P<user>[-a-z]+)/location/gears/$', gearsloc),
    #(r'^user/(?P<user>[-a-z]+)/location/wifi/$', wifilocation),
    #(r'^user/location/$', 'user.location'),
    
    #(r'^backend/home.html$',backend_home),
    #(r'^backend/location.html$',backend_location),
    #(r'^backend/locationways.html$',backend_locationways),
    #(r'^backend/photo.html$',backend_photo),
    
    #Servir imagenes, css, codigo javascript.. y todo lo que no requiere procesamiento alguno desde este directorio:
    #(r'^resources/(?P<path>.*)$','django.views.static.serve', {'document_root': '/var/www/server/resources/'}),
    (r'^version/', 'social.rest.views.version'),
    (r'^social/', include('social.rest.urls')),
    (r'^site_media/images/photos', 'social.rest.views.forbbiden_photo'), #respect users privacy
    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
            {'document_root': MEDIA_ROOT}),
    #(r'^social/', include('elgg.urls')),
    #(r'^user/location/$', 'user.location'),

    # agregador
    (r'^agregador/', include('agregador.urls')),
    (r'^apps/', include('apps.agregator.urls')),
)


def look_up_apps():

    apps_dir = join (BASEDIR, APPS_DIR)
    dirs = os.listdir(apps_dir)
    
    pat = urlpatterns
    for dir in dirs:
        if os.path.isdir(join(apps_dir, dir)) and dir[0] not in  ('.', '_'):
            url = r'^%s/' % dir
            urls_file = '%s.%s.urls' % (APPS_DIR, dir)
            pat = pat + patterns('', (url, include(urls_file)))

    return pat

try:
    urlpatterns = look_up_apps()
    pass
except:
    pass 
